package com.kaichaohulian.baocms.activity_newcreate;


import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.kaichaohulian.baocms.R;
import com.kaichaohulian.baocms.app.MyApplication;
import com.kaichaohulian.baocms.base.BaseMyActivity;
import com.kaichaohulian.baocms.http.HttpUtil;
import com.kaichaohulian.baocms.http.Url;
import com.kaichaohulian.baocms.newmodel.IndexSongDetailModel;
import com.kaichaohulian.baocms.utils.DBLog;
import com.kaichaohulian.baocms.view.ShowDialog;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.kaichaohulian.baocms.R.id.text_ren;

public class IndexHelpQuActivity extends BaseMyActivity {

    int userID;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.exit_layout)
    LinearLayout exitLayout;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.center_title_tv)
    TextView centerTitleTv;
    @BindView(R.id.navigation_bar)
    RelativeLayout navigationBar;
    @BindView(R.id.img_xu)
    ImageView imgXu;
    @BindView(R.id.text_title)
    TextView textTitle;
    @BindView(R.id.text_status)
    TextView textStatus;
    @BindView(R.id.text_time)
    TextView textTime;
    @BindView(R.id.text_static)
    TextView textStatic;
    @BindView(R.id.text_choulao)
    TextView textChoulao;
    @BindView(R.id.user_lianxir)
    TextView userLianxir;
    @BindView(R.id.text_phone)
    TextView textPhone;
    @BindView(R.id.text_xuqiushuoming)
    TextView textXuqiushuoming;
    @BindView(R.id.recycle_pic)
    RecyclerView recyclePic;
    @BindView(R.id.text_shouhuoren)
    TextView textShouhuoren;
    @BindView(R.id.textshouhuolianxi)
    TextView textshouhuolianxi;
    @BindView(R.id.text_shouhuo_addr)
    TextView textShouhuoAddr;
    @BindView(text_ren)
    TextView textRen;
    @BindView(R.id.text_shenqing)
    TextView textShenqing;
    @BindView(R.id.title_linLayout)
    LinearLayout titleLinLayout;
    @BindView(R.id.text_quhuo)
    TextView text_quhuo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help_qu_index);
        ButterKnife.bind(this);

        userID = MyApplication.getInstance().UserInfo.getUserId();
        getnewXuqiu();
    }

    public void getnewXuqiu() {

        final RequestParams params = new RequestParams();
        params.put("userId", userID);
        params.put("demandId", getIntent().getStringExtra("demandId"));

        HttpUtil.post(Url.detail_xuqiu, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                Log.d(response.toString(), "333333333333333");
//                XuqiuDetailModel
                IndexSongDetailModel xuqiuDetailModel = new IndexSongDetailModel();
                Gson gson = new Gson();
                xuqiuDetailModel = gson.fromJson(response.toString(), IndexSongDetailModel.class);
                textTime.setText(xuqiuDetailModel.getDataObject().getCreatedTime());

                if (xuqiuDetailModel.getDataObject().getStatus().equals("0")) {
                    textStatus.setText("申请中");
                } else if (xuqiuDetailModel.getDataObject().getStatus().equals("1")) {
                    textStatus.setText("同意");
                } else if (xuqiuDetailModel.getDataObject().getStatus().equals(" 2")) {
                    textStatus.setText("拒接");
                } else {
                    textStatus.setText("未申请");
                }

                textXuqiushuoming.setText("送货相关说明：" + xuqiuDetailModel.getDataObject().getRemark());
                //给人打电话的吧
                textRen.setText(xuqiuDetailModel.getDataObject().getPhoneNumber());
                textChoulao.setText("¥" + xuqiuDetailModel.getDataObject().getReward());
                textStatic.setText(xuqiuDetailModel.getDataObject().getKeyWord());
//取货联系人user_lianxir
                userLianxir.setText(xuqiuDetailModel.getDataObject().getGoodsUser());
//取货人的电话
                textPhone.setText(xuqiuDetailModel.getDataObject().getGoodsNumber());
                //取货地址
                text_quhuo.setText(xuqiuDetailModel.getDataObject().getGoodsAddress());
//收货联系人text_shouhuoren
                textShouhuoren.setText(xuqiuDetailModel.getDataObject().getReceiver());
//收货联系电话textshouhuolianxi
                textshouhuolianxi.setText(xuqiuDetailModel.getDataObject().getReceiverNumber());
                //收货地址text_shouhuo_addr
                textShouhuoAddr.setText(xuqiuDetailModel.getDataObject().getReceiverAddress());

            }

            @Override
            public void onFinish() {
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                DBLog.e("tag", statusCode + ":" + responseString);
                ShowDialog.dissmiss();

            }

            @Override
            public void onCancel() {
//                Toast.makeText(getActivity(), "请求取消", Toast.LENGTH_SHORT).show();
                ShowDialog.dissmiss();
            }
        });
    }

    @OnClick({R.id.iv_back, R.id.exit_layout, R.id.tv_title, R.id.center_title_tv, R.id.navigation_bar, R.id.img_xu, R.id.text_title, R.id.text_status, R.id.text_time, R.id.text_static, R.id.text_choulao, R.id.user_lianxir, R.id.text_phone, R.id.text_xuqiushuoming, R.id.recycle_pic, R.id.text_shouhuoren, R.id.textshouhuolianxi, R.id.text_shouhuo_addr, text_ren, R.id.text_shenqing, R.id.title_linLayout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.exit_layout:
                break;
            case R.id.tv_title:
                break;
            case R.id.center_title_tv:
                break;
            case R.id.navigation_bar:
                break;
            case R.id.img_xu:
                break;
            case R.id.text_title:
                break;
            case R.id.text_status:
                break;
            case R.id.text_time:
                break;
            case R.id.text_static:
                break;
            case R.id.text_choulao:
                break;
            case R.id.user_lianxir:
                break;
            case R.id.text_phone:
                break;
            case R.id.text_xuqiushuoming:
                break;
            case R.id.recycle_pic:
                break;
            case R.id.text_shouhuoren:
                break;
            case R.id.textshouhuolianxi:
                break;
            case R.id.text_shouhuo_addr:
                break;
            case text_ren:
                break;
            case R.id.text_shenqing:
                getRequest();
                break;
            case R.id.title_linLayout:
                break;
        }
    }
//最热需求

    public void getRequest() {

        final RequestParams params = new RequestParams();
        params.put("userId", getIntent().getStringExtra("fabuid"));
        params.put("demandId", getIntent().getStringExtra("demandId"));
        params.put("applyUserId", MyApplication.getInstance().UserInfo.getUserId());
        HttpUtil.post(Url.My_ShenQing, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                Log.d(response.toString(), "333333333333333");

                Gson gson = new Gson();


            }

            @Override
            public void onFinish() {
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                DBLog.e("tag", statusCode + ":" + responseString);
                ShowDialog.dissmiss();

            }

            @Override
            public void onCancel() {
//                Toast.makeText(getActivity(), "请求取消", Toast.LENGTH_SHORT).show();
                ShowDialog.dissmiss();
            }
        });
    }
}
